require "Common/define"
require "Logic/Config"
require "Common/functions"
---@class RedDotsTaskTimeBoxHandler
RedDotsTaskTimeBoxHandler ={};
local this = RedDotsTaskTimeBoxHandler;

function RedDotsTaskTimeBoxHandler.init()

    CloseEvent(Config.EventType.TimeBoxUpdate,this.update);
    ListenEvent(Config.EventType.TimeBoxUpdate,this.update);
    if this.timerId then
        utimer.remove(this.timerId)
    end
    this.timerId = utimer.timeCall(this.CheckReward,1000,-1)
    this.hasReward = false
    return this;
end

-- 参数1： 任务类型。
function RedDotsTaskTimeBoxHandler.getFlag(...)
    if ...~=nil then
        return Config.RedDotsFlagState.None;
    end
    if logicMgr.FuncOpenManager.isOpen(Config.FuncOpenType.TimeBoxAll,false) then
        local param = {...}
        if #param == 0 or param[1] == 1 then
            if this.hasReward then
                return Config.RedDotsFlagState.Needful
            end
        end

    end
    return Config.RedDotsFlagState.None;
end


function RedDotsTaskTimeBoxHandler.update()
    this.CheckReward()
end
function RedDotsTaskTimeBoxHandler.CheckReward()
    local flag = TimeBoxHandler.HasReward()
    if flag ~= this.hasReward then
        RedDotsManager.addBroadcast(Config.RedDotsType.TaskTimeBox);
        this.hasReward = flag
    end
end